/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package fuzzyLogic;

/**
 *
 * @author CygiDawid
 */
public abstract class VariableSet {
    private final String _name;
    protected double[] _values;
    protected double _from = 0d;
    protected double _to = 0d;
    protected double _step = 0d;
    
    
    public VariableSet(String name, double from, double to, double step) {
        if (from > to) {
            throw new IllegalArgumentException();
        }
        
        _name = name;
        _from = from;
        _to = to;
        _step = step;
    }
    
    
    public double getAffiliation(double value) {
        double result = 0d;
        
        int i = (int)((value - _from) * (1 / _step));
        return _values[i];
    }
    protected abstract double calcValue(double value);
    
    
    protected void createSet() {
        int stepCount = (int)((_to - _from) / _step) + 1;
        _values = new double[stepCount];
        for (int i = 0; i < stepCount; i++) {
            _values[i] = calcValue(_from + i * _step);
        }
    }
    
    /*
    protected boolean isOut(double value) {
        if (value < _from || value > _to) {
            return true;
        }
        
        return false;
    }*/
    
    
    public String getName() {
        return _name;
    }
    
    /*
    protected double[] getFunction(double x1, double y1, double x2, double y2) {
        double a = (y2 - y1) / (x2 - x1);
        double b = y1 - a * x1;
        
        return new double[] { a, b };
    }*/
    
}
